package com.dataaccess.dataaccess.web.service;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseService;
import com.dataaccess.dataaccess.model.SanjiangyunAlarmAllDeviceInfo;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.web.mapper.SanjiangyunAlarmAllDeviceInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: YangYu
 * @ClassName: SanJiangYunService
 * @Date: Created in 15:51 2022/10/26
 * @Description: 三江云服务
 */
@Service
public class SanJiangYunService extends BaseService {
    @Resource
    public DeviceAboatSmokeService deviceAboatService;
    @Resource
    private SanjiangyunAlarmAllDeviceInfoMapper sanjiangyunAlarmAllDeviceInfoMapper;
    @Resource
    private DeviceAboatGasService deviceAboatGasService;
    @Resource
    private AutoNetworkAlarmDeviceDataChangedService autoNetworkAlarmDeviceDataChangedService;
    /**
     * @Author YangYu
     * @Description 三江云所有数据
     * @Date Created in 16:03 2022/10/26
     * @Param [jsonParam]
     */

    public RespEntity sanJiangYun(JSONObject jsonParam) throws Exception {
        //设备类型
        String deviceType = jsonParam.getStr("deviceType");
        //报警数据
        SanjiangyunAlarmAllDeviceInfo sanjiangyunAlarmAllDeviceInfo =  new SanjiangyunAlarmAllDeviceInfo();
        sanjiangyunAlarmAllDeviceInfo.setId(UUID.randomUUID().toString());
        sanjiangyunAlarmAllDeviceInfo.setJsondata(jsonParam.toString());
        //烟感
        if (deviceType.equals("H388N") || deviceType.equals("H390N") || deviceType.equals("H390NB")){
            sanjiangyunAlarmAllDeviceInfo.setType("3");
            sanjiangyunAlarmAllDeviceInfoMapper.insert(sanjiangyunAlarmAllDeviceInfo);
            deviceAboatService.sanjiangSmoke(jsonParam);
        //燃气
        }else if (deviceType.equals("JD-GAS")){
            sanjiangyunAlarmAllDeviceInfo.setType("4");
            sanjiangyunAlarmAllDeviceInfoMapper.insert(sanjiangyunAlarmAllDeviceInfo);
            deviceAboatGasService.sanjiangGas(jsonParam);
        //用户传输装置
        }else if (deviceType.equals("JK-CS-01")){
            sanjiangyunAlarmAllDeviceInfo.setType("5");
            sanjiangyunAlarmAllDeviceInfoMapper.insert(sanjiangyunAlarmAllDeviceInfo);
            autoNetworkAlarmDeviceDataChangedService.sanjiangAutoNetwork(jsonParam);
        }
        return RespEntity.success();
    }
}
